﻿using System;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using System.Data;

namespace ASPItalia.ModelVirtualCasting.EntityFramework {
	public class UserRoleRepository : BaseRepository<UserRole>, IUserRoleRepository {
		public UserRoleRepository(IContextContainer container)
			: base(container) {
		}

		public void InsertOnSubmit(UserRole entity) {
			CurrentObjectSet.AddObject(entity);
		}

		public void Update(UserRole entity) {
			CurrentObjectSet.Attach(entity);
			Context.ChangeObjectState(entity, EntityState.Modified);
		}

		public void DeleteOnSubmit(UserRole entity) {
			CurrentObjectSet.DeleteObject(entity);
		}

		public void SubmitChanges() {
			SaveChanges();
		}

		public IQueryable<UserRole> GetAll() {
			return CurrentObjectSet;
		}

		public IQueryable<UserRole> Where(Expression<Func<UserRole, bool>> predicate) {
			return CurrentObjectSet.Where(predicate);
		}

		public long Count(Expression<Func<UserRole, bool>> predicate) {
			return CurrentObjectSet.Count(predicate);
		}

		public IUserRoleRepository Include(string path) {
			CurrentObjectSet.Include(path);
			return this;
		}

		#region IReadOnlyRepository<IUserRoleRepository,UserRole> Members


		public IUserRoleRepository EnableLazyLoading() {
			SetLazyLoading(true);
			return this;
		}

		public IUserRoleRepository DisableLazyLoading() {
			SetLazyLoading(false);
			return this;
		}

		#endregion
	}
}